package com.hhhn.wk.main.tab2.view.xiangqing.adapter;

import android.app.Activity;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.hhhn.wk.R;
import com.hhhn.wk.utils.Constants;
import com.hhhn.wk.utils.SysUtils;


import java.util.ArrayList;

public class ClassifyGridViewAdapter extends BaseAdapter {

	Activity context;
	ArrayList<String> list;
	public Bitmap bitmaps[];
//	private FinalBitmap finalImageLoader;
	private int wh;

	public ClassifyGridViewAdapter(Activity context, ArrayList<String> data) {
		this.context=context;
		this.wh=(SysUtils.getScreenWidth(context)- SysUtils.Dp2Px(context, 99))/3;
		this.list=data;
//		this.finalImageLoader=FinalBitmap.create(context);
//		this.finalImageLoader.configLoadingImage(R.mipmap.logo_rrb_hui);//图片加载完成前显示的图片
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}


	@Override
	public View getView(final int position, View view, ViewGroup arg2) {
		Holder holder;
		if (view==null) {
			view= LayoutInflater.from(context).inflate(R.layout.classify_list_grid_item, null);
			holder=new Holder();
			holder.imageView=(ImageView) view.findViewById(R.id.imageView);
			view.setTag(holder);
		}else {
			holder= (Holder) view.getTag();
		}
		///finalImageLoader.display(holder.imageView, list.get(position));
//		ImageOptions options = new ImageOptions.Builder()
//				.setSize(DensityUtil.dip2px(120), DensityUtil.dip2px(80))//设置宽高
//				.setRadius(DensityUtil.dip2px(5))//设置圆角
//				.setImageScaleType(ImageView.ScaleType.CENTER_CROP)//图片拉伸
//				.setUseMemCache(false)//使用缓存
//				.setLoadingDrawableId(R.mipmap.logo)//加载时显示的图片
//				.setFailureDrawableId(R.mipmap.logo)//加载失败显示的图片
//				.build();
//		x.image().bind(holder.imageView, Constants.HTTPIMG+list.get(position), options);



		Glide.with(context).load(Constants.HTTPIMG+ list.get(position))
				.placeholder(R.mipmap.logo)
				.error(R.mipmap.logo)//圆角图片
				.diskCacheStrategy(DiskCacheStrategy.ALL)
				.crossFade().into(holder.imageView);



//		AbsListView.LayoutParams param = new AbsListView.LayoutParams(wh,wh);
//		view.setLayoutParams(param);
		return view;
	}

	class Holder{
		ImageView imageView;
	}


}